package io.github.cmmplb.seata.nacos.common.db.config;//package com.cmmplb.cmmondb.config;
//
//import feign.RequestInterceptor;
//import feign.RequestTemplate;
//import io.seata.core.context.RootContext;
//import org.apache.commons.lang.StringUtils;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpRequest;
//import org.springframework.http.client.ClientHttpRequestExecution;
//import org.springframework.http.client.ClientHttpRequestInterceptor;
//import org.springframework.http.client.ClientHttpResponse;
//
//import java.io.IOException;
//import java.util.Collections;
//
///**
// * @author penglibo
// * @date 2021-05-13 16:09:09
// * @since jdk 1.8
// */
//
//public class SeataRestInterceptor implements RequestInterceptor, ClientHttpRequestInterceptor {
//
//    @Override
//    public void apply(RequestTemplate requestTemplate) {
//        String xid = RootContext.getXID();
//        if (!StringUtils.isEmpty(xid)) {
//            System.out.println("全局事务唯一ID：" + xid);
//            requestTemplate.header(SeataAutoConfiguration.SEATA_XID, xid);
//        }
//    }
//
//    @Override
//    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
//        String xid = RootContext.getXID();
//        if (!StringUtils.isEmpty(xid)) {
//            HttpHeaders headers = request.getHeaders();
//            headers.put(SeataAutoConfiguration.SEATA_XID, Collections.singletonList(xid));
//        }
//        return execution.execute(request, body);
//    }
//}
